package gp_Print;


import java.util.ArrayList;

import com.sun.jna.Library;
import com.sun.jna.Native;
public class Print {
	public static  ArrayList arrayList = new ArrayList();
	
    public interface TscLibDll extends Library {
        TscLibDll INSTANCE = (TscLibDll) Native.loadLibrary ("TSCLIB", TscLibDll.class);
        int about ();
        int openport (String pirnterName);
        int closeport ();
        int sendcommand (String printerCommand);
        int setup (String width,String height,String speed,String density,String sensor,String vertical,String offset);
        int downloadpcx (String filename,String image_name);
        int barcode (String x,String y,String type,String height,String readable,String rotation,String narrow,String wide,String code);
        int printerfont (String x,String y,String fonttype,String rotation,String xmul,String ymul,String text);
        int clearbuffer ();
        int printlabel (String set, String copy);
        int formfeed ();
        int nobackfeed ();
        int windowsfont (int x, int y, int fontheight, int rotation, int fontstyle, int fontunderline, String szFaceName, String content);
    }
    
    public static void main  (String args[]){
       //TscLibDll.INSTANCE.about();
    	
    	add_ArrayList();
    	test(arrayList);
 
   }
    public static void test(ArrayList arrayList){
    	int a =arrayList.size();
    	System.out.println("a的值是"+a);
    	if (a%2==0) {
    		a=a/2;
		} else {
			a=(a+1)/2;
		}
    	//TscLibDll.INSTANCE.about();
        TscLibDll.INSTANCE.openport("Gprinter  GP-9025T");
        TscLibDll.INSTANCE.sendcommand("REM ***** This is a test by JAVA. *****");  
        //条码纸之前为40*30 两个在一起是80*30 中间有空白，要考虑到空白问题
        TscLibDll.INSTANCE.setup("80", String.valueOf(a*30), "5", "5", "0", "2", "0");  
        TscLibDll.INSTANCE.clearbuffer();  
        //TscLibDll.INSTANCE.sendcommand("PUTPCX 550,10,\"UL.PCX\"");  
        
        for (int i = 3; i < arrayList.size()+3; i++) {
        	
        	System.out.println("get_array"+arrayList.get(i-3));
				if(i%2!=0){
    	TscLibDll.INSTANCE.barcode("0", String.valueOf(((i-3)/2)*280), "128", "50", "1", "0", "1.8", "2",String.valueOf(arrayList.get(i-3))); 
				System.out.println("1111111111111111111"+arrayList.get(i-3));
				}
				else if(i%2==0){
		TscLibDll.INSTANCE.barcode("340", String.valueOf(((i-3)/2)*280), "128", "50", "1", "0", "1.8", "2",String.valueOf(arrayList.get(i-3)));
				System.out.println("2222222222222222222"+arrayList.get(i-3));
				}
		}
        TscLibDll.INSTANCE.printlabel("1", "1");  
        TscLibDll.INSTANCE.closeport();     
    } 
    
   public static  void add_ArrayList(){
	  
	   for (int i = 10000000; i < 10000010; i++) {
		   System.out.println("set_array"+i);
		  arrayList.add(Integer.valueOf(i));
	}   
   }
}

